<?php

declare(strict_types=1);

namespace app\shop\controller\api\activity;

use think\Request;
use app\shop\controller\api\ShopBase;
use sheep\exception\SheepException;
use think\facade\Db;
use app\shop\model\activity\Activity as ActivityModel;

class Activity extends ShopBase
{

    // 活动详情
    public function detail(Request $request, $id)
    {
        $activity = ActivityModel::findOrFail($id);

        if ($activity->classify == 'promo') {
            $rules = $activity['rules'];
            $rules['simple'] = true;
            $tags = app('activity')->formatRuleTags($rules, $activity['type']);

            $activity['tag'] = $tags[0] ?? '';
            $activity['tags'] = $tags;
    
            $texts = app('activity')->formatRuleTexts($rules, $activity['type']);
            $activity['texts'] = $texts;
        }

        return success('获取成功', $activity);
    }
}
